package com.chima.service.impl;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import com.chima.dao.EmployeeDao;
import com.chima.domain.Department;
import com.chima.domain.DepartmentCoffer;
import com.chima.domain.Employees;
import com.chima.domain.HsCheckDepartment;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.domain.Performance;
import com.chima.domain.Position;
import com.chima.service.EmployeeService;
public class EmployeeServiceImp implements EmployeeService {
	
	private EmployeeDao employeeDao;
	
	public EmployeeDao getEmployeeDao() {
		return employeeDao;
	}

	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}

	public Employees findEmployeesBypwdAndName(String name, String password) {
		
		return employeeDao.findEmployeesBypwdAndName(name, password);
	}

	public PageResponseBean findEmployee(PageRequestBean pageRequestBean) {
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = employeeDao.findByTotalCount(pageRequestBean.getDept());
		// 获取分页查询条件
//		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Employees.class);
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<Employees> employees = employeeDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(employees);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public void saveEmployees(Employees employees) {
		employeeDao.save(employees);
		
	}

	public void updateEmployees(Employees employees) {
		employeeDao.update(employees);
		
	}

	public void deleteEmployees(int id) {
		employeeDao.delete(id);
	}
	public Employees findEmployeesByName(String name) {
		
		return employeeDao.findByName(name);
	}
	public Employees findEmployeesById(int id) {
		
		return employeeDao.findById(id);
	}
	public List<Employees> findEmployeesByDeparmet(int id) {
		
		return employeeDao.findByDepartment(id);
	}
	public void addRole(int emp, int role,String datapermision) {
		employeeDao.addRole(emp, role,datapermision);
	}

	public List<Employees> findALL() {
		
		return employeeDao.findALL();
	}

	public Employees findEmployeesByNameAndDepart(String name, Department d) {
		
		return employeeDao.findByNameAndDpepart(name, d);
	}

	public List<Employees> findEmployeesByposition(int position) {
		
		return employeeDao.findByPosition(position);
	}

	public List<Employees> findMiddleEmployees(int position,String  datapermission) {
		
		return employeeDao.findMiddleEmp(position, datapermission);
	}

	public List<Employees> findEmpBypositionAndDept(int position, int dept) {
		
		return employeeDao.findByDepartmentAndPosition(dept, position);
	}

	public PageResponseBean findGeneralEmployee(PageRequestBean pageRequestBean) {
		
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = employeeDao.findGeneralByTotalCount(pageRequestBean.getDept());
		// 获取分页查询条件
//		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Employees.class);
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<Employees> employees = employeeDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(employees);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public void addEMPRole(int emp, int role) {
	
		employeeDao.addEMPRole(emp, role);
		
	}

	public List<Position> ListallPosition() {
		
		return employeeDao.ListallPosition();
	}

	public void updatePosition(int id, double coffer) {
		
		employeeDao.updatePosition(id, coffer);
	}

	public Employees findBypositionAndDept(int position, int dept) {
		
		return employeeDao.findempByDepartmentAndPosition(dept, position);
	}

	@Override
	public List<Department> finddepartmentByflag1(int i) {
		// TODO Auto-generated method stub
		return employeeDao.finddepartmentByflag1(i) ;
	}

	@Override
	public Double findtotalRewardbydateanddeptname(String searchdate,
			String name) {
		// TODO Auto-generated method stub
		return employeeDao.findtotalRewardbydateanddeptname(searchdate,name) ;
	}

	@Override
	public List<HsCheckDepartment> findHsCheckDepartmentBymonthandflag(
			String searchdate1, int i) {
		// TODO Auto-generated method stub
		return employeeDao.findHsCheckDepartmentBymonthandflag(searchdate1,i);
	}

	@Override
	public List<HsCheckDepartment> findHsCheckDepartmentBymonth(
			String searchdate1) {
		return employeeDao.findHsCheckDepartmentBymonth(searchdate1);
	}

	@Override
	public void updateHsCheckDepartmentByMonth(String searchdate1) {
          employeeDao.updateHsCheckDepartmentByMonth(searchdate1);
		
	}

	@Override
	public void deleteEmpMoneyBydeptidAndDate(int deptid, String searchdate1) {
		employeeDao.deleteEmpMoneyBydeptidAndDate(deptid,searchdate1);
		
	}

	@Override
	public void saveorupdateEmpmoney(Performance performance) {
		// TODO Auto-generated method stub
		employeeDao.saveorupdateEmpmoney(performance);
	}

	@Override
	public void addorupdateHsCheckDepartment(HsCheckDepartment hsCheckDepartment) {
		// TODO Auto-generated method stub
		employeeDao.addorupdateHsCheckDepartment( hsCheckDepartment);
	}

	@Override
	public int findrates(int deptid, String searchdate1) {
		// TODO Auto-generated method stub
		return employeeDao.findrates(deptid,  searchdate1);
	}

	@Override
	public double findtotalkaoping(int searchdepartment, String searchdate) {
		// TODO Auto-generated method stub
		return employeeDao.findtotalkaoping(searchdepartment,searchdate);
	}

	@Override
	public Department finddepartmentByid(int searchdepartment) {
		// TODO Auto-generated method stub
		return employeeDao.finddepartmentByid(searchdepartment);
	}

	@Override
	public DepartmentCoffer findDepartmentCofferbydeptname(String name) {
		// TODO Auto-generated method stub
		return employeeDao.findDepartmentCofferbydeptname(name);
	}

	@Override
	public double findtotalPostCompetent(int searchdepartment, String searchdate) {
		// TODO Auto-generated method stub
		return employeeDao.findtotalPostCompetent(searchdepartment,searchdate);
	}

	@Override
	public List<Employees> findEmployeesmangerByDeparmet(int searchdepartment) {
		// TODO Auto-generated method stub
		return employeeDao.findEmployeesmangerByDeparmet(searchdepartment);
	}

	@Override
	public List<Employees> findListzubydeptid(int deptId) {
		return employeeDao.findListzubydeptid(deptId);
		// TODO Auto-generated method stub
	}

	@Override
	public void addEMPzu(int empID, String name) {
		employeeDao.addEMPzu(empID,name);
		// TODO Auto-generated method stub
		
	}

	

	
	
}
